package com.cs.base.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.StyleRes;
import androidx.appcompat.app.AlertDialog;
import androidx.viewbinding.ViewBinding;

import com.cs.base.R;

/**
 * @ClassName: BaseDialog
 * @Date: 2021/12/15
 * @Author: CS
 * @Description:
 */
public abstract class BaseDialog<VB extends ViewBinding> extends AlertDialog implements View.OnClickListener{

    protected Context context;
    //ViewBinding
    protected VB binding;

    public BaseDialog(Context context) {
        super(context, R.style.closeDialog);
        this.context=context;
    }

    public BaseDialog(Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        this.context=context;
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        //初始化ViewDataBinding，设置ContentView
        binding = getViewBinding();
        View rootView = binding.getRoot();
        setContentView(rootView);
        //初始化view
        initView();
    }

    /**
     * 初始化视图
     */
    protected abstract void initView();


    @Override
    public void onClick(View v) {}

    /**
     * 初始化要加载的布局资源ID, 获取子类布局ViewBinding
     * 此函数优先执行于onCreate()可以做window操作
     */
    protected abstract VB getViewBinding();

}
